import React, { Component } from 'react';
import Comment from './Comment';
import PropTypes from 'prop-types';
import { List } from 'antd';

class CommentList extends Component {
  static propTypes = {
    comments: PropTypes.array,
    onDeleteComment: PropTypes.func
  }
  
  static defaultProps = {
    comments: []
  }
  
  handleDeleteComment(index) {
    if(this.props.onDeleteComment) {
      this.props.onDeleteComment(index);
    }
  }
  
  render() {
    return (
      <div>
        <List 
          itemLayout="horizontal"
          dataSource={this.props.comments} 
          renderItem={(comment, i) => 
            <Comment 
              key={comment.createdTime} 
              index={i} 
              comment={comment} 
              onDeleteComment={this.handleDeleteComment.bind(this)} />}
        />
      </div>
    );
  }
}

export default CommentList;